package com.exercise.widgets.viewpager2.fragments

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.exercise.widgets.databinding.FragmentNormalBinding

class NormalFragment : Fragment() {
    private var _binding: FragmentNormalBinding? = null
    private val binding: FragmentNormalBinding get() =  _binding!!

    private var mLabel: String? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mLabel = arguments?.getString(PARAM_LABEL) ?: "Unknown"
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        _binding = FragmentNormalBinding.inflate(layoutInflater, container, false)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        binding.tvLabel.text = mLabel
    }

    companion object {
        const val PARAM_LABEL = "label"
        fun newInstance(label: String): NormalFragment {
            return NormalFragment().apply {
                arguments = Bundle().apply {
                    putString(PARAM_LABEL, label)
                }
            }
        }
    }
}